using UnityEngine;
using System.Collections;

public class TowerController : MonoBehaviour {
	
	public GameObject projectile;
	ArrayList minionList;
	bool readyToFire;
	float timer;

	// Use this for initialization
	void Start () {
		
		minionList = new ArrayList();
		readyToFire = true;
		timer = 0;
	
	}
	
	// Update is called once per frame
	void Update () {
		
		timer += Time.deltaTime;
		if (timer >= 1)
		{
			readyToFire = true;
		}
		if (readyToFire && minionList.Count > 0)
		{
			//Debug.Log("fire");
			GameObject projectileClone = (GameObject)Instantiate (projectile, transform.position, Quaternion.identity);
			projectileClone.GetComponent<Projectile>().SetTarget((GameObject)minionList[0], this.gameObject);
			projectileClone.GetComponent<Projectile>().SetID(Projectile.IDCounter);
			timer = 0;
			readyToFire = false;
		}

		if (minionList.Count > 0 && minionList[0] == null)
		{
			minionList.RemoveAt(0);
		}
	
	}
	
	public void AddMinionTarget(GameObject c)
	{
		//Debug.Log ("Minion Added");
		minionList.Add(c);
	}
}
